package com.wteam.dragon.shop.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wteam.dragon.shop.pojo.bean.BrandHome;
import com.wteam.dragon.shop.service.BrandHomeService;
import com.wteam.dragon.system.aop.log.log.Log;
import com.wteam.dragon.system.basebean.bean.ResultMessage;
import com.wteam.dragon.system.basebean.vo.PageVo;
import com.wteam.dragon.system.util.BeanUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author 陈晓辉
 * @Date 2021/3/25 17:04
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "品牌推荐")
@RequestMapping("brandHome")
public class BrandHomeController {
    private final BrandHomeService brandHomeService;

    @Log("批量添加推荐品牌")
    @ApiOperation("批量添加推荐品牌")
    @PostMapping("addBrandHome")
    @PreAuthorize("@el.check('addBrandHome')")
    public ResultMessage addBrandHome(@RequestParam List<Long> ids){
        return brandHomeService.addBrandHome(ids);
    }

    @Log("批量删除推荐品牌")
    @ApiOperation("批量删除推荐品牌")
    @DeleteMapping("delBrandHome")
    @PreAuthorize("@el.check('delBrandHome')")
    public ResultMessage delBrandHome(@RequestParam List<Long> ids){
        return brandHomeService.delBrandHome(ids);
    }

    @Log("设置排序")
    @ApiOperation("设置排序")
    @PutMapping("editBrandHomeSort")
    @PreAuthorize("@el.check('editBrandHomeSort')")
    public ResultMessage editBrandHomeSort(Long id, Long sort){
        return brandHomeService.editBrandHomeSort(id, sort);
    }

    @Log("分页获得推荐品牌")
    @ApiOperation("分页获得推荐品牌")
    @GetMapping("pageBrandHome")
    @PreAuthorize("@el.check('pageBrandHome')")
    public ResultMessage pageBrandHome(PageVo<BrandHome> pageVo, String brandName, Integer recommendStatus){
        Page<BrandHome> page = BeanUtil.fromPage(pageVo);
        return brandHomeService.pageBrandHome(page, brandName, recommendStatus);
    }

    @Log("批量设为推荐和批量取消推荐")
    @ApiOperation("批量设为推荐和批量取消推荐")
    @PutMapping("editBrandHomeStatus")
    @PreAuthorize("@el.check('editBrandHomeStatus')")
    public ResultMessage editBrandHomeStatus(@RequestParam List<Long> ids, Integer status){
        return brandHomeService.editBrandHomeStatus(ids, status);
    }

}
